#!user/bin/env python3
# -- coding: utf-8 --
# @Createtime：2022/5/15
# @Updatetime：
# @Author：Test008
# @File：ModifyStuInfo.py
# @Description：修改学生信息
from config import filename

import os.path


def show():
    pass


def modify():
    show()
    if os.path.exists(filename):
        with open(filename, 'r', encoding='utf-8') as rfile:
            student_old = rfile.readlines()
            print(type(student_old), student_old)
    else:
        return
    student_id = input('请输入学生ID：')
    with open(filename, 'w', encoding='utf-8') as wfile:
        for item in student_old:
            d = dict(eval(item))
            print(type(d), d)
            if d['id'] == student_id:
                print(f'找到{student_id}学生，可以修改学生信息。')
                while True:
                    try:
                        d['name'] = input('请输入姓名：')
                        d['english'] = input('请输入英语成绩：')
                        d['python'] = input('请输入Python成绩：')
                        d['java'] = input('请输入Java成绩：')
                    except:
                        print('您的输入有误，请重新输入!!!')
                    else:
                        break
                wfile.write(str(d) + '\n')
                print('修改成功')
            else:
                wfile.write(str(d) + '\n')
        answer = input('是否需要修改其他学生信息? y/n\n')
        if answer == 'y':
            modify()


if __name__ == '__main__':
    modify()
